#! /usr/bin/env python
# -*- coding: utf-8 -*-

from playwright.sync_api import Page

from common.base_page import BasePage
from common.logger import logger
from locators.majorHazardSourceSafety.olMonitorWarn.monitorIndexManage.loc_add import LocAdd
from locators.majorHazardSourceSafety.olMonitorWarn.monitorIndexManage.loc_delete import LocDelete
from locators.majorHazardSourceSafety.olMonitorWarn.monitorIndexManage.loc_disable import LocDisable
from locators.majorHazardSourceSafety.olMonitorWarn.monitorIndexManage.loc_edit import LocEdit
from locators.majorHazardSourceSafety.olMonitorWarn.monitorIndexManage.loc_enable import LocEnable
from locators.majorHazardSourceSafety.olMonitorWarn.monitorIndexManage.loc_query import LocQuery


class MonitorIndexManage(BasePage):

    def __init__(self, page: Page):
        super().__init__(page)
        self.switch_menu('重大危险源安全管理')
        self.switch_menu('在线监测预警')
        self.switch_menu('监测预警指标管理')

    def query_total_list(self, index_name, obj_type, index_type, status):
        logger.info('开始监测预警指标管理查询测试')
        logger.info('输入指标名称')
        self.fill(LocQuery.loc_index_name, index_name)
        logger.info('选择关联对象类型')
        self.select(LocQuery.loc_obj_type, obj_type)
        logger.info('选择关联指标类型')
        self.select(LocQuery.loc_index_type, index_type)
        logger.info('选择启用状态')
        self.select(LocQuery.loc_status, status)
        self.click(LocQuery.loc_query, exact=True)

    def reset(self):
        """
        测试重置
        :return:
        """
        self.click(LocQuery.loc_reset, exact=True)

    def add_index(self, index_name, obj_type, index_type, index_code, high_high, high, low, low_low,
                  index_unit, point_name):
        logger.info('开始监测预警指标新增测试')
        logger.info('点击新增按钮')
        self.click(LocAdd.loc_add_button)
        logger.info('输入指标名称')
        self.fill(LocAdd.loc_index_name, index_name)
        logger.info('选择关联对象类型')
        self.select(LocAdd.loc_obj_type, obj_type)
        logger.info('选择关联指标类型')
        self.select(LocAdd.loc_index_type, index_type)
        logger.info('输入关联指标编码')
        self.fill(LocAdd.loc_index_code, index_code)
        logger.info('输入上上限阈值')
        self.fill_number(LocAdd.loc_high_high, high_high)
        logger.info('输入上限阈值')
        self.fill_number(LocAdd.loc_high, high)
        logger.info('输入下限阈值')
        self.fill_number(LocAdd.loc_low, low)
        logger.info('输入下下限阈值')
        self.fill_number(LocAdd.loc_low_low, low_low)
        logger.info('选择阈值单位')
        self.select(LocAdd.loc_index_unit, index_unit)
        logger.info('选择适用点位')
        # self.select(LocAdd.loc_point_name, point_name)
        self.select_single_tree(LocAdd.loc_point_name, point_name)
        logger.info('点击确定')
        self.click(LocAdd.loc_submit)

    def edit_index(self, index_name):
        logger.info('开始监测预警指标编辑测试')
        self.click(LocEdit.loc_edit_button)
        logger.info('清空指标名称')
        self.clear(LocEdit.loc_index_name)
        logger.info('输入新的指标名称')
        self.fill(LocEdit.loc_index_name, index_name)
        logger.info('点击确定')
        self.click(LocEdit.loc_submit)

    def delete_index(self, value):
        logger.info('开始监测预警指标编辑测试')
        logger.info('勾选数据')
        self.select_row_checkbox(value)
        logger.info('点击删除按钮')
        self.click(LocDelete.loc_delete_button)
        logger.info('点击确定')
        self.click(LocDelete.loc_submit)

    def enable_index(self, value):
        logger.info('开始监测预警指标启用测试')
        logger.info('勾选数据')
        self.select_row_checkbox(value)
        logger.info('点击启用按钮')
        self.click(LocEnable.loc_enable_button)

    def disables_index(self, value):
        logger.info('开始监测预警指标禁用测试')
        logger.info('勾选数据')
        self.select_row_checkbox(value)
        logger.info('点击禁用按钮')
        self.click(LocDisable.loc_disable_button)
